package com.wu01.demo.newdemo.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @author wubingcang
 * @desc
 * @date 2024年04月21日 16:21
 */
public class SignAgreementConverter implements Converter<Boolean> {
    @Override
    public Class<?> supportJavaTypeKey() {
        return Boolean.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Boolean convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty,
                                     GlobalConfiguration globalConfiguration) throws Exception {
        if("否".equals(cellData.getStringValue())){
            return Boolean.FALSE;
        }else if("是".equals(cellData.getStringValue())){
            return Boolean.TRUE;
        }
        return null;
    }

    @Override
    public WriteCellData<?> convertToExcelData(Boolean value, ExcelContentProperty contentProperty,
                                               GlobalConfiguration globalConfiguration) throws Exception {
        if(value.equals(Boolean.TRUE)){
            return new WriteCellData<>("是");
        }else if(value.equals(Boolean.FALSE)){
            return new WriteCellData<>("否");
        }
        return null;
    }
}
